from collections import namedtuple

# 匿名元组的定义方式
People = ("Alice", 23, 99)

# 解包元组
name, age, score = People
print("name=", name, "age=", age, "score=", score)
print(
    f"通过索引访问元组,People[0]={People[0]},People[1]={People[1]},People[2]={People[2]}",
)


# 具名元组的使用,定义一个名称为PersonTuple的元组，拥有三个字段，name,age,score
Person = namedtuple("PersonTuple", ["name", "age", "score"])

person = Person("Alice", 20, 98)

# type(person)=<class '__main__.PersonTuple'>

print("name=", person.name, "age =", person.age, "score=", person.score)


# 解包元组
name, age, score = person
print("name=", name, "age =", age, "score=", score)

# 遍历元组

for item in person:
    print(item)
